<template>
  <TableView
    ref="tableView"
    :table-attrs="{ api: getPage, descs: ['createTime'], payloadStyle: 'body' }"
    :search-model="searchForm"
    :toolbar-attrs="{ buttons: ['slot'] }">
    <template #toolbar-button>
      <ToolbarButton icon="el-icon-download" type="primary" label="导出" @click="exportExcel" />
    </template>
    <template #columns>
      <TableColumn label="借阅人" prop="borrower" />
      <TableColumn label="使用单位" prop="useUnitName" />
      <TableColumn label="借阅时间" prop="borrowDateTime" />
      <TableColumn label="归还时间" prop="returnDateTime" />
      <TableColumn label="图书编码" prop="bookCode" />
      <TableColumn label="图书名称" prop="name" />
      <TableColumn label="作者" prop="author" />
      <TableColumn label="出版日期" prop="publishDate" />
      <TableColumn label="编录号" prop="catalogCode" />
    </template>
    <template #search-form>
      <FormInput v-model="searchForm.name" prop="name" label="图书名称" />
      <FormInput v-model="searchForm.borrower" prop="borrower" label="借阅人" />
      <FormSelect
        v-model="searchForm.status"
        prop="status"
        label="归还状态"
        :options="[
          { label: '已归还', value: 3 },
          { label: '未归还', value: 2 }
        ]" />
    </template>
  </TableView>
</template>

<script>
  import { borrowHistory2 as getPage } from '@/module/library/bookApply/api'
  import { services } from '@/config'

  export default {
    name: 'BookStatistic',
    data() {
      return {
        searchForm: {
          name: '',
          borrower: '',
          status: null
        }
      }
    },
    methods: {
      getPage,
      exportExcel() {
        this.$downBlobFile(
          `${services.personnelService}applyBook/export`,
          null,
          '借阅记录.xlsx',
          'post',
          this.$refs.tableView.getPageQuery()
        )
      }
    }
  }
</script>
